#encoding='gbk'

import random
import unittest

class MyClass(object):
    @classmethod
    def sum(self,a,b):
        return a+b
    @classmethod
    def div(self,a,b):
        return a/b
    @classmethod
    def return_None(self):
        return None

class MyTest(unittest.TestCase):
    def test_assertEqual(self):
        try:
            a,b=1,2
            sum=3
            self.assertEqual(a+b,sum,'断言失败，%s+%s!=%s' %(a,b,sum))
        except AssertionError as e:
            print(1,e)
    def test_assertNotEqual(self):
        try:
            a,b=1,2
            sum=3
            self.assertNotEqual(a-b,sum,'断言失败，%s-%s==%s' %(a,b,sum))
        except AssertionError as e:
            print(1,e)
    def test_assertTrue(self):
        try:
            self.assertTrue(1==1,'表达式为假')
        except AssertionError as e:
            print(1,e)
    def test_assertFalse(self):
        try:
            self.assertFalse(3==1,'表达式为真')
        except AssertionError as e:
            print(1,e)
    def test_assertIs(self):
        try:
            a= 12
            b= a
            self.assertIs(a,b,'%s与%s不属于同一对象' %(a,b))
        except AssertionError as e:
            print(1,e)
    def test_assertIsNot(self):
        try:
            a= 12
            b= 'test'
            self.assertIsNot(a,b,'%s与%s属于同一对象' %(a,b))
        except AssertionError as e:
            print(1,e)
    def test_assertIsNone(self):
        try:
            result= MyClass.return_None()
            self.assertIsNone(result,'not is None')
        except AssertionError as e:
            print(1,e)
    def test_assertIsNotNone(self):
        try:
            result= MyClass.sum(2,5)
            self.assertIsNotNone(result,'is None')
        except AssertionError as e:
            print(1,e)
    def test_assertIn(self):
        try:
            strA= 'this is a test'
            strB= 'is'
            self.assertIn(strB,strA,'%s包含在%s中' %(strB,strA))
        except AssertionError as e:
            print(1,e)
    def test_assertNotIn(self):
        try:
            strA= 'this is a test'
            strB= 'isa'
            self.assertNotIn(strB,strA,'%s包含在%s中' %(strB,strA))
        except AssertionError as e:
            print(1,e)

    def test_assertIsInstance(self):
        try:
            x= MyClass
            y= object
            #strB= 'isa'
            self.assertIsInstance(x,y,'%s的类型不是%s' %(x,y))
        except AssertionError as e:
            print(1,e)


if __name__=='__main__':
    unittest.main()